package com.cac.demo.controller.msAoMatchBill;

import com.alibaba.fastjson.JSON;
import com.cac.demo.service.msAoMatchBill.MsAoMatchBillService;
import com.cac.demo.util.adapter.PageParameter;
import com.cac.demo.util.adapter.QueryReqBean;
import com.cac.demo.util.adapter.QueryRespBean;
import com.cac.demo.util.adapter.ResponseMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @program test-curd
 * @description AO物料配套清单服务接口
 * @author: LSL
 * @create: 2022-08-29-15-58
 **/
@RestController
@RequestMapping("/MsAoMatchBill")
public class MsAoMatchBillRest {
    @Autowired
    private MsAoMatchBillService msAoMatchBillService;

    /**
     * 分页查询AO物料配套清单服务接口
     * @param map
     * @return
     */
    @PostMapping("/searchByPage")
    public ResponseMsg<QueryRespBean<HashMap>> searchByPage(@RequestBody Map map){
        ResponseMsg<QueryRespBean<HashMap>> responseMsg = new ResponseMsg<>();
        String page = JSON.toJSONString(map.get("pageParameter"));
        PageParameter pageParameter = JSON.parseObject(page,PageParameter.class);
        String DTO = JSON.toJSONString(map.get("searchParams"));
        HashMap searchParams = JSON.parseObject(DTO, HashMap.class);
        QueryReqBean<HashMap> queryReqBean = new QueryReqBean<>();
        queryReqBean.setPageParameter(pageParameter);
        queryReqBean.setSearchParams(searchParams);
        QueryRespBean<HashMap> result = msAoMatchBillService.searchByPage(queryReqBean);
        responseMsg.setResponseBody(result);
        return responseMsg;
    }
    /**
     * 分页查询AO物料未配套清单
     * @param map
     * @return
     */
    @PostMapping("/searchMsAoMatchBill")
    public ResponseMsg<QueryRespBean<HashMap>> searchByPage(@RequestBody HashMap map) {
        ResponseMsg<QueryRespBean<HashMap>> responseMsg = new ResponseMsg<>();
        String msTaskAoId = (String) map.get("msTaskAoId");
        String param = JSON.toJSONString(map.get("pageParameter"));
        PageParameter pageParameter = JSON.parseObject(param, PageParameter.class);
        QueryReqBean<HashMap> queryReqBean = new QueryReqBean<>();
        queryReqBean.setPageParameter(pageParameter);
        QueryRespBean<HashMap> result = msAoMatchBillService.searchMsAoMatchBill(queryReqBean, msTaskAoId);
        responseMsg.setResponseBody(result);
        return responseMsg;
    }
}
